<?php
// ----- >> Extends From Template
class thisPDF extends PDF{
	function Header(){}
	function Footer(){}
}


// ----- >> Init
$fpdf = new thisPDF('P','mm','Letter');
$fpdf->AddPage();
$fpdf->SetLeftMargin(8);

$fpdf->Ln(0);
$ln_header_y_top	= $fpdf->GetY();

$date = date('d-M-Y');

// ----- >> Header

function terbilang_get_valid($str,$from,$to,$min=1,$max=9){
      $val=false;
      $from=($from<0)?0:$from;
      for ($i=$from;$i<$to;$i++){
        if (((int) $str{$i}>=$min)&&((int) $str{$i}<=$max)) $val=true;
      }
      return $val;
  } 

  function terbilang_get_str($i,$str,$len){
      $numA=array("","satu","dua","tiga","empat","lima","enam","tujuh","delapan","sembilan");
      $numB=array("","se","dua ","tiga ","empat ","lima ","enam ","tujuh ","delapan ","sembilan ");
      $numC=array("","satu ","dua ","tiga ","empat ","lima ","enam ","tujuh ","delapan ","sembilan ");
      $numD=array(0=>"puluh",1=>"belas",2=>"ratus",4=>"ribu", 7=>"juta", 10=>"milyar", 13=>"triliun");
      $buf="";
      $pos=$len-$i;
      switch($pos){
        case 1:
            if (!terbilang_get_valid($str,$i-1,$i,1,1))
              $buf=$numA[(int) $str{$i}];
          break;
        case 2: case 5: case 8: case 11: case 14:
            if ((int) $str{$i}==1){
              if ((int) $str{$i+1}==0)
                $buf=($numB[(int) $str{$i}]).($numD[0]);
              else
                $buf=($numB[(int) $str{$i+1}]).($numD[1]);
            }
            else if ((int) $str{$i}>1){
                $buf=($numB[(int) $str{$i}]).($numD[0]);
            }       
          break;
        case 3: case 6: case 9: case 12: case 15:
            if ((int) $str{$i}>0){
                $buf=($numB[(int) $str{$i}]).($numD[2]);
            }
          break;
        case 4: case 7: case 10: case 13:
            if (terbilang_get_valid($str,$i-2,$i)){
              if (!terbilang_get_valid($str,$i-1,$i,1,1))
                $buf=$numC[(int) $str{$i}].($numD[$pos]);
              else
                $buf=$numD[$pos];
            }           else if((int) $str{$i}>0){
              if ($pos==4)
                $buf=($numB[(int) $str{$i}]).($numD[$pos]);
              else
                $buf=($numC[(int) $str{$i}]).($numD[$pos]);
            }
          break;
      }
      return $buf;
  }
  function toTerbilang($nominal){
      $buf="";
      $str=$nominal."";
      $len=strlen($str);
      
      for ($i=0;$i<$len;$i++){
        $buf=trim($buf)." ".terbilang_get_str($i,$str,$len);
      }
      return trim($buf);
  }

    // ------ >> add Font : sample antqua

	function fpdf_font_info($metric_file) {
	  $name = false;
	  require($metric_file);
	  if($name) {
	    return strpos($name, "-") === false ? array($name, 'Regular') : explode("-", $name);
	  } else {
	    return array(false, false);
	  }
	}

	function available_fonts($fpdf) {
	  $names = array();
	  $path = $fpdf->_getfontpath();
	  $metric_files = glob("{$path}*.php");

	  foreach($metric_files as $f) {
	    list($name, $style) = fpdf_font_info($f);
	    if($name) {
	      $names[] = "$name ($style)";
	    }
	  }

	  return $names;
	}

	function register_fonts($fpdf) {
	  $path = $fpdf->_getfontpath();
	  $metric_files = glob("{$path}*.php");

	  foreach($metric_files as $f) {
	    list($base_name, $style_name) = fpdf_font_info($f);
	    if($base_name) {
	      switch($style_name) {
	        case 'Bold':
	          $style = 'B';
	          break;
	        case 'Italic':
	          $style = 'I';
	          break;
	        case 'BoldItalic':
	          $style = 'BI';
	          break;
	        default:
	          $style = '';
	      }
	      $fpdf->AddFont($base_name, $style, basename($f));
	    }
	  }
	}

	register_fonts($fpdf);

//------->> End Font

// ----- >> Header
$fpdf->Ln(2);
$fpdf->SetFont('calibri','','14');
//$fpdf->SetFont('calibri','',14);
$fpdf->Cell(0,4,"Data Pembelian Produk",0,0,'L');

$fpdf->Ln(7);



// ----- >> Data Master
$fpdf->SetFont('calibri','',10);
$fpdf->Cell(60,5,"",0,0,'L');
$fpdf->Cell(130,5,"Cilegon, ".$date,0,0,'R');
$fpdf->Line(9, 25, 200-3, 25); // 197mm from each edge
$fpdf->Ln(7);

$fpdf->Cell(60,5,"Nama Pelanggan",0,0,'L');

$fpdf->Ln(5);
$fpdf->Cell(95,5,$data['nama_perusahaan'],0,0,'L');
$fpdf->Cell(50,5,"CUSTCODE",0,0,'L');
$fpdf->Cell(2,5,":",0,0,'L');
$fpdf->Cell(10,5,$data['kode_customer'],0,0,'L');

$fpdf->Ln(5);

$fpdf->MultiCell(95,5,$data['alamat'],0,'L');

$fpdf->Cell(95,5,$data['kota']."  ".$data['kode_pos'],0,0,'L');
$fpdf->Cell(50,5,"Contact Person",0,0,'L');
$fpdf->Cell(2,5,":",0,0,'L');
$fpdf->Cell(10,5,$data['nama'],0,0,'L');
$fpdf->Ln(10);

$fpdf->Line(9, 55, 200-3, 55); // 197mm from each edge
$fpdf->Cell(100,5,"Uraian   :",0,0,'L');
$fpdf->Ln(10);

$num = $data['harga'] ;
$formattedNum = number_format($num);

$fpdf->Cell(60,5,"Nama Inventori ",0,0,'L');
$fpdf->Cell(80,5,"   :  ".$data['nama_inventori'],0,0,'L');
$fpdf->Cell(10,5,":",0,0,'L');
$fpdf->Cell(10,5,"Rp. " ,0,0,'L');
$fpdf->Cell(21,5,$formattedNum.",- ",0,0,'R');
$fpdf->Ln(5);

$num1 = $num * $data['banyak'] ;

$fpdf->Cell(60,5,"Jumlah Pembelian ",0,0,'L');
$fpdf->Cell(80,5,"   :  ".$data['banyak']."  Unit ",0,0,'L');
$fpdf->Cell(10,5,":",0,0,'L');
$fpdf->Cell(10,5,"Rp. " ,0,0,'L');
$fpdf->Cell(21,5,number_format($num1).",-",0,0,'R');
$fpdf->Ln(4.5);

$ppn = $num1 * 0.1;

$fpdf->Cell(140,5,"PPN 10%",0,0,'L');
$fpdf->Cell(10,5,":",0,0,'L');
$fpdf->Cell(10,5,"Rp. " ,0,0,'L');
$fpdf->Cell(25,5,number_format($ppn).",-(+)" ,0,0,'R');
$fpdf->Line(158, 80, 193, 80); // 197mm from each edge
$fpdf->Ln(4.5);

$num2 = $num1 + $ppn ;
$formattedNum2 = number_format($num2);

$fpdf->Cell(140,5,"TOTAL",0,0,'L');
$fpdf->Cell(10,5,":",0,0,'L');
$fpdf->Cell(10,5,"Rp. " ,0,0,'L');
$fpdf->Cell(21.7,5,$formattedNum2.",- ",0,0,'R');
$fpdf->Ln(15);

$terbilang = toTerbilang($num2);

$fpdf->Cell(140,5,"Terbilang  :",0,0,'L');
$fpdf->Ln(5);
$fpdf->SetFont("");
$fpdf->SetFont('calibri','BI',12);
$fpdf->Cell(50,5,"#".$terbilang." rupiah #",0,0,'L');
$fpdf->Ln(10);
$fpdf->SetFont("");

$fpdf->SetFont('calibri','',10);
$fpdf->Cell(140,5,"Pembayaran Via Rekening",0,0,'L');
$fpdf->Ln(10);

$fpdf->Cell(140,5,"BANK MANDIRI - Cilegon Anyer",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"No. Rek : 163-0000-25346-1",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"a/n : PRIMKOKAS Cyber-K",0,0,'L');
$fpdf->Ln(10);

$fpdf->Cell(140,5,"*Jika mentransfer pembayaran mohon mencantumkan kode pelanggan ini : ".$data['kode_customer']." pada berita acara",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"Hormat Kami, ",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"Cyber-K PRIMKOKAS",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"Information System Division",0,0,'L');
$fpdf->Ln(20);
$fpdf->Image(APPPATH . 'file/media/ttd_isp.jpg');


$fpdf->Ln(5);
$fpdf->Cell(140,5,"Maulana Rusli",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"Information System Div. Manager",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"Tembusan :",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5," - Accounting Dept.",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5," - Finance Dept.",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5," - Arsip",0,0,'L');




/*
// ----- >> Data Master
$fpdf->SetFont('Arial','',10);
$fpdf->Cell(30,5,"Kode Client",0,0,'L');
$fpdf->Cell(2,5,":",0,0,'L');
$fpdf->Cell(50,5,$data['kode_customer'],0,0,'L');
$fpdf->Ln(7);

$fpdf->Cell(30,5,"Nama Client",0,0,'L');
$fpdf->Cell(2,5,":",0,0,'L');
$fpdf->Cell(40,5,$data['nama'],0,0,'L');
$fpdf->Ln(7);

$fpdf->SetFont('Arial','',10);
$fpdf->Cell(30,5,"Nama Perusahaan",0,0,'L');
$fpdf->Cell(2,5,":",0,0,'L');
$fpdf->Cell(20,5,$data['nama_perusahaan'],0,0,'L');
$fpdf->Ln(7);

$fpdf->Cell(30,5,"Kode Produk",0,0,'L');
$fpdf->Cell(2,5,":",0,0,'L');
$fpdf->Cell(20,5,$data['kode_inventori'],0,0,'L');
$fpdf->Ln(7);

$fpdf->SetFont('Arial','',10);
$fpdf->Cell(30,5,"Nama Produk",0,0,'L');
$fpdf->Cell(2,5,":",0,0,'L');
$fpdf->Cell(60,5,$data['nama_inventori'],0,0,'L');
$fpdf->Ln(7);

$numharga = $data['harga'] ;
$formattedNum = number_format($numharga);

$fpdf->Cell(30,5,"Harga Produk",0,0,'L');
$fpdf->Cell(2,5,":",0,0,'L');
$fpdf->Cell(50,5,"RP. ".$numharga.",-",0,0,'L');
$fpdf->Ln(7);

$fpdf->Cell(30,5,"Jumlah Pembelian",0,0,'L');
$fpdf->Cell(2,5,":",0,0,'L');
$fpdf->Cell(20,5,$data['banyak'],0,0,'L');
$fpdf->Ln(7);

$numtotal = $data['total_bayar'] ;
$formattedNum = number_format($numtotal);
$fpdf->Cell(30,5,"Total Pembayaran",0,0,'L');
$fpdf->Cell(2,5,":",0,0,'L');
$fpdf->Cell(50,5,"RP. ".$numtotal.",-",0,0,'L');
$fpdf->Ln(10);

$fpdf->Cell(140,5,"Pembayaran Via Rekening",0,0,'L');
$fpdf->Ln(10);

$fpdf->Cell(140,5,"BANK MANDIRI - Cilegon Anyer",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"No. Rek 	: 163-0000-25346-1",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"a/n	: PRIMKOKAS Cyber-K",0,0,'L');
$fpdf->Ln(10);

$fpdf->Cell(140,5,"*Jika mentransfer pembayaran mohon mencantumkan kode pelanggan ini : ".$data['kode_customer']." pada berita acara",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"Hormat Kami, ",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"Cyber-K PRIMKOKAS",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"Information System Division",0,0,'L');
$fpdf->Ln(20);

$fpdf->Cell(140,5,"Cilegon, ".$date,0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"Maulana Rusli",0,0,'L');
$fpdf->Ln(5);
$fpdf->Image(APPPATH . 'file/media/ttd_isp.jpg');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"Information System Div. Manager",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"Tembusan :",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5," - Accounting Dept.",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5," - Finance Dept.",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5," - Arsip",0,0,'L');
*//*
$fpdf->Cell(30,5,"Keterangan",0,0,'L');
$fpdf->Cell(2,5,":",0,0,'L');
$fpdf->Cell(20,5,$data['keterangan'],0,0,'L');
$fpdf->Ln(4);*/






echo $fpdf->Output('Data Pembelian Produk'." "."$date"." ".'.pdf', 'I');
exit();
?>